package com.chinasofti.SSM.tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

/**
 * 自定义转换器 ---实现时间数据无法自动转换绑定
 * @author zp
 *
 */
public class StringToDateConverter implements Converter<String, Date>{
    private String pattern;
    
    /**
     * 构造注入
     * @param pattern
     */
    public StringToDateConverter(String pattern){
    	this.pattern=pattern;
    }
	@Override
	public Date convert(String  str) {
		Date date = null;
		try {
			date = new SimpleDateFormat(pattern).parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
   
}
